package com.okilo.online.app.weight.font

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Typeface
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.graphics.toColorInt

/**
 * OkiloLOan
 *
 * @Author wwdeng
 * @CreateTime: 2024/12/26 21:34
 * @Annotation：
 */
class OkiloRbtMediumDeleteTextView : AppCompatTextView {
    private var flag = true

    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    override fun setTypeface(tf: Typeface?) {
        super.setTypeface(tf)
    }

    override fun setTypeface(tf: Typeface?, style: Int) {
        super.setTypeface(Typeface.createFromAsset(context.assets, "fonts/Rbt-Medium.ttf"))
    }

    @SuppressLint("DrawAllocation")
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        if (flag) {
            val paint = Paint().apply {
                // 设置直线的颜色
                color = "#ffc3c3c3".toColorInt()
                // 设置直线没有锯齿
                isAntiAlias = true
                // 设置线宽
                strokeWidth = 1f
            }
            // 设置直线位置
            canvas.drawLine(paddingStart.toFloat(), (height / 2).toFloat(), width.toFloat(), (height / 2).toFloat(), paint)
        }
    }

    /**
     * true显示删除线     false不显示删除线
     * @param flag
     * @return flag
     */
    fun setTv(flag: Boolean): Boolean {
        this.flag = flag
        return flag
    }
}